//  关键点在不同的条件下修改搜索框的宽度
//  DiscoverSearchView.swift
//  WeiboSwift
//
//  Created by Apple13 on 16/7/13.
//  Copyright © 2016年 yupeng. All rights reserved.
//

import UIKit

class DiscoverSearchView: UIView,UITextFieldDelegate {

    @IBOutlet weak var cancelButton: UIButton!
    
    @IBOutlet weak var textField: UITextField!
    
    @IBOutlet weak var textFieldRight: NSLayoutConstraint!
    
    //加载xib
    class func searchView() -> DiscoverSearchView{
        
        
        return UINib(nibName: "DiscoverSearchView",bundle: nil).instantiateWithOwner(nil, options: nil).last! as! DiscoverSearchView
        
    }
    
    
    @IBAction func cancelButtonAction(sender: AnyObject) {
        print("点击了取消按钮--取消了第一响应")
       
        printLog()
        
        //取消第一响应
//        self.endEditing(true)
        textField.resignFirstResponder()
        
       
         textFieldRight.constant = 0
        
        UIView.animateWithDuration(0.2) {
            self.layoutIfNeeded()
        }
        
        
    }

    //MARK: -  text 代理
    
    func textFieldDidBeginEditing(textField: UITextField) {
       
        textFieldRight.constant = cancelButton.width
        
        print("开始搜索")
        UIView.animateWithDuration(0.2) {
            self.layoutIfNeeded()
        }
    }
    
    
}
